//
//  ViewController.m
//  UI-14-HomeWorkLws
//
//  Created by GivenBmli on 16/8/2.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"
#import "imageCollectionViewCell.h"
#import "CategoryCollectionReusableView.h"
#import "ColumnCollectionReusableView.h"
#import "StyleCollectionReusableView.h"
#import "FrienfCollectionReusableView.h"
#import "StayleimageCollectionViewCell.h"
#define kCollectionViewReture @"reture"
#define kCollectionViewReusableHeader @"reuseableView"
#define kCollectionViewReusableHeaderNoCell @"headerView"
#define kCollectionViewReusableHeaderNoStyleCell @"StyleCell"
#define kCollectionViewReusableHeaderNoFrienfCell @"FrienfCell"
#define randomColor [UIColor colorWithRed:arc4random() % 256 / 255.0f green:arc4random() % 256 / 255.0f blue:arc4random() % 256 / 255.0f alpha:1];
@interface ViewController ()<UICollectionViewDelegate , UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UICollectionViewFlowLayout *flow =[[UICollectionViewFlowLayout alloc]init];
    
    UICollectionView *colletiView = [[UICollectionView  alloc]initWithFrame:self.view.bounds collectionViewLayout:flow];
//    CGFloat witdh = (CGRectGetWidth(self.view.bounds) - 10)/3;
    //    item 大小
//    flow.itemSize = CGSizeMake(witdh, witdh);
    //    列间距
    flow.itemSize = CGSizeMake(CGRectGetWidth(self.view.bounds) / 2 - 7.5, 120);

    flow.minimumLineSpacing = 5;
    //    行间距
    flow.minimumInteritemSpacing = 5;
    flow.headerReferenceSize = CGSizeMake(0, 50);
    colletiView.delegate = self;
    colletiView.dataSource = self;
    colletiView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:colletiView];
    
    [colletiView registerClass:[imageCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewReture];
    
    [colletiView registerClass:[StyleCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeaderNoStyleCell];
    
    [colletiView registerClass:[FrienfCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeaderNoFrienfCell];

    
    [colletiView registerClass:[CategoryCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeader ];
   
    [colletiView registerClass:[ColumnCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeaderNoCell];
    
    
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 400);
        
    }else {
        return CGSizeMake(0, 50);
    }
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        
        ColumnCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeaderNoCell forIndexPath:indexPath];
        //        reusableView.backgroundColor = [UIColor redColor];
        return reusableView;
    }else if (indexPath.section == 1){
            
            CategoryCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeader forIndexPath:indexPath];
            //    reusableView.backgroundColor = [UIColor redColor];
            return reusableView;
            
        
    }else if (indexPath.section == 2){
        StyleCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeaderNoStyleCell forIndexPath:indexPath];
        //    reusableView.backgroundColor = [UIColor redColor];
        return reusableView;

    }else{
        FrienfCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusableHeaderNoFrienfCell forIndexPath:indexPath];
        //    reusableView.backgroundColor = [UIColor redColor];
        return reusableView;

        
    }
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    
    return 6;
    
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    imageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewReture forIndexPath:indexPath];
    cell.backgroundColor = randomColor;
    
    return cell;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
